const express=require('express');
const path=require('path');
const fs=require('fs');
const multer=require('multer');
const upload=multer({dest:'file_upload/'});
const router=express.Router();
// upload.single上传单个文件
router.post('/upload',upload.single('avatar'),(req,res)=>{
	let file=req.file;
	let oldName=file.originalname;
	// 获取文件的扩展名
	let extname=path.extname(oldName);
	// 获取文件上传的路径
	let Nname=file.path;
	// 拼接
	let newName=Nname+extname;
	fs.renameSync(Nname,newName);
	res.send(`文件上传成功 文件名为:${file.filename}${extname}`);
	// console.log(newName);
})
module.exports=router;